/*
	author: TangQiao , Wind @ Beijing Normal University

	problem name: Heavy Cargo

	source :  BNU Online Judge
	
	problem type: 图论 
	
	problem description: 找出从A到B地的路中路的载重最大一条.
	
	problem solution: FLOYD算法.
	
	date : 2005.7.16 北师大个人练习赛
	
*/
#include <stdio.h>
#include <string.h>
#include <math.h>

int n,r;
char name[201][40];
int map[201][201];
int min;
int now;

int getsite(char *s)
{
	int i;
	for (i=1;i<=now;i++)
		if (strcmp(name[i],s)==0)
			return i;
	return -1;
	
}


main()
{
	int i, j, k;
	char s1[40],s2[40];
	int dis, icase=0,a,b;
	while (1)
	{
		scanf("%d%d", &n, &r);
		if (n==0) break;

		memset(name,0,sizeof(name));
		memset(map,0,sizeof(map));
//		for (i=0;i<=200;i++)
//			for (j=0;j<=200;j++)
//				map[i][j]=20000;
		
		now=0;
		for (i=1;i<=r;i++)
		{
			scanf("%s%s%d", s1, s2, &dis);
			a=getsite(s1);
			if (a==-1) 
			{
				a=++now;
				strcpy(name[now],s1);
			}
			b=getsite(s2);
			if (b==-1) 
			{
				b=++now;
				strcpy(name[now],s2);
			}
			map[a][b]=map[b][a]=dis;

		}
		scanf("%s%s", s1, s2);
		a=getsite(s1);
		b=getsite(s2);
		for (k=1;k<=n;k++)
			for (i=1;i<=n;i++)
				if (k!=i)
					for (j=i+1;j<=n;j++)
						if (j!=i && j!=k && map[i][k]!=0 && map[k][j]!=0
							&& (min=map[i][k]>map[k][j]?map[k][j]:map[i][k])>map[i][j])
							map[i][j]=map[j][i]=min;
		printf("Scenario #%d\n",++icase);						
		printf("%d tons\n\n", map[a][b]);


	}

	return 0;
}